﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MissionImpossible.Custom;

namespace MissionImpossible
{
  public partial class SearchDialog : Form
  {
    public SearchDialog()
    {
      InitializeComponent();
      SetUpHelp();
      yearInputField.YearValidated += yearInputField_YearValidated;
    }

    void yearInputField_YearValidated(object sender, YearValidationEvent e)
    {
      if(!e.YearCorrect)
      {
        string errorMessage = string.Format("Wrong year: please set year between {0:D} and {1:D}.",
                                      e.MinYear, e.MaxYear);
        errorProvider1.SetError(yearInputField, errorMessage);
      }
      else
      {
        errorProvider1.SetError(yearInputField, "");
      }
    }


    private void SetUpHelp()
    {
      helpProvider1.SetShowHelp(titleTextBox, true);
      helpProvider1.SetShowHelp(countryTextBox, true);
      helpProvider1.SetShowHelp(yearInputField, true);
      helpProvider1.SetShowHelp(directorTextBox, true);
      helpProvider1.SetShowHelp(actorTextBox, true);
      SetHelpStringWithWildcards(titleTextBox, "Enter title of film.");
      SetHelpStringWithWildcards(countryTextBox, "Enter country of film.");
      SetHelpStringWithWildcards(directorTextBox, "Enter director of film.");
      SetHelpStringWithWildcards(actorTextBox, "Enter actor of film.");
      helpProvider1.SetHelpString(yearInputField, "Enter year of film.");
    }

    private void SetHelpStringWithWildcards(Control ctrl, string description)
    {
      var titleHelp = GenerateHelpStringWithWildchards(description);
      helpProvider1.SetHelpString(ctrl, titleHelp);
    }

    private static string GenerateHelpStringWithWildchards(string description)
    {
      string wildchards = "You can use * and ? wildcards.";
      string titleHelp = string.Format("{0} {1}", description, wildchards);
      return titleHelp;
    }

    private void button1_Click(object sender, EventArgs e)
    {
      Hide();
    }

    private void textBox1_TextChanged(object sender, EventArgs e)
    {

    }

    private void textBox2_TextChanged(object sender, EventArgs e)
    {

    }
  }
}
